﻿@page "/starting"
@using HandlerContextOptions
@using Environment.Interfaces
@layout EmptyLayout
@inject IGatewatDateBase iGatewatDateBase



<div class="login-NavLogin">
    <div style="padding:30px">
        <Card Bordered="true" Title=@("环境初始化") Style="width:450px" Hoverable="true">
            <Body>
                <Form Model="@request" OnFinish="HandleSubmit">
                    <FormItem Label=" 登 录 名 ">
                        <AntDesign.Input Placeholder="请填写管理员登录名" Size="large" ReadOnly="true" @bind-Value="@context.Administrator">
                            <Prefix><Icon Type="user" /></Prefix>
                        </AntDesign.Input>
                    </FormItem>
                    <FormItem Label="登录密码">
                        <AntDesign.Input Placeholder="请填写8到20位数管理员登录密码" Size="large" @bind-Value="@context.AdministratorPassward">
                            <Prefix><Icon Type="lock" /></Prefix>
                        </AntDesign.Input>
                    </FormItem>
                    <FormItem Label="警告邮箱">
                        <AntDesign.Input Placeholder="请填写警告邮箱" Size="large" @bind-Value="@context.Email">
                            <Prefix><Icon Type="mail" /></Prefix>
                        </AntDesign.Input>
                    </FormItem>
                    <FormItem Label="(SA) 密码">
                        <AntDesign.Input Placeholder="请填写8到20位数据库登录密码" Size="large" @bind-Value="@context.Passward">
                            <Prefix><Icon Type="lock" /></Prefix>
                        </AntDesign.Input>
                    </FormItem>
                    <FormItem Label="端 口 号 ">
                        <AntDesign.Input Placeholder="请输入1000~65535开放端口号,默认2433" Size="large" @bind-Value="@context.Port">
                            <Prefix><Icon Type="fork" /></Prefix>
                        </AntDesign.Input>
                    </FormItem>
                    <Space Direction="DirectionVHType.Vertical" Style="width:100%">
                        <SpaceItem>
                            <Spin Spinning="Loading" Size="large" Tip="初始化中，请勿关闭浏览器...">
                                <Button Type="primary" HtmlType="submit" Class="submit" Size="large" Block>提&nbsp;交</Button>
                            </Spin>
                        </SpaceItem>
                    </Space>
                </Form>
            </Body>
        </Card>
    </div>
</div>

@code {

    bool Loading { get; set; }

    CreateGatewayDateBaseRequset request = new CreateGatewayDateBaseRequset();

    WindowsHelper windows;
    protected string inputvalue = "";

    protected override async Task OnAfterRenderAsync(bool firstRender)
    {
        windows = new WindowsHelper(jSRuntime);
        await windows.HideLoadingAsync();
        await windows.SetTitleAsync("Starting");
    }


    protected async Task HandleSubmit()
    {
        Loading = true;

        //await Task.Delay(2000);
        // 处理数据库

        await base.InvokeAsync(async () => {
            var result = await iGatewatDateBase.CreateInstance(request);
            await this.Notification(result);
            Loading = false;
            base.StateHasChanged();
        });
    }

    private async Task Notification(CreateGatewayDateBaseResult result)
    {
        if (result.IsSuccessful)
        {
            await Task.Delay(1000);
            navigationManager.NavigateTo("/User/Login");

            var task = notice.Success(new NotificationConfig
            {
                Message = "操作成功.",
                Description = "准备跳转至登陆页面",
                Duration = 2
            });
        }
        else
        {
            var task = notice.Error(new NotificationConfig
            {
                Message = "操作失败",
                Description = result.Description,
                Duration = 2
            });
        }
    }

}

<style>
    .login-NavLogin {
        position: absolute;
        left: 50%;
        top: 40%;
        transform: translate(-50%, -50%);
    }
</style>